package com.aloda.ojsandbox.pojo.dto;

import com.aloda.ojsandbox.pojo.entity.JudgeInfo;
import com.aloda.ojsandbox.pojo.enums.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 执行代码响应体
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExecuteCodeResponse {

    /**
     * 输出集合
     */
    private List<String> outputList;

    /**
     * 接口信息
     */
    private String message;

    /**
     * 执行状态
     */
    private Integer status;

    /**
     * 判题信息
     */
    private JudgeInfo judgeInfo;

    /**
     * 成功
     * @param outputList
     * @param judgeInfo
     * @return
     */
    public static ExecuteCodeResponse success(List<String> outputList, JudgeInfo judgeInfo) {
        ExecuteCodeResponse executeCodeResponse = new ExecuteCodeResponse();
        executeCodeResponse.status = ResponseEnum.SUCCESS.getStatus();
        executeCodeResponse.message = ResponseEnum.SUCCESS.getMessage();
        executeCodeResponse.outputList = outputList;
        executeCodeResponse.judgeInfo = judgeInfo;
        return executeCodeResponse;
    }

    /**
     * 自定义失败类型
     * @param responseEnum
     * @return
     */
    public static ExecuteCodeResponse error(ResponseEnum responseEnum) {
        ExecuteCodeResponse executeCodeResponse = new ExecuteCodeResponse();
        executeCodeResponse.status = responseEnum.getStatus();
        executeCodeResponse.message = responseEnum.getMessage();
        return executeCodeResponse;
    }

    /**
     * 自定义失败类型
     * @param message
     * @return
     */
    public static ExecuteCodeResponse error(Integer status ,String message) {
        ExecuteCodeResponse executeCodeResponse = new ExecuteCodeResponse();
        executeCodeResponse.status = status;
        executeCodeResponse.message = message;
        return executeCodeResponse;
    }

    /**
     * 默认失败类型
     * @return
     */
    public static ExecuteCodeResponse error() {
       return error(ResponseEnum.FAILURE);
    }
}
